package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;

import com.sky.vo.SetmealVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    @ApiOperation("分页查询套餐的功能")
    @GetMapping("/page")
    public Result<PageResult> pageSelectSetmeal(SetmealPageQueryDTO setmealPageQueryDTO) {
        log.info("正在执行根据分页查询套餐列表.........查询信息为:{}", setmealPageQueryDTO);
        PageResult p = setmealService.pageSelectSetmeal(setmealPageQueryDTO);
        return Result.success(p);
    }

    @ApiOperation("根据id查询套餐的功能")
    @GetMapping("/{id}")
    public Result<SetmealVO> byidSelectSetmeal(@PathVariable Long id) {
        log.info("正在执行根据id查询套餐的方法........id为:{}", id);
        SetmealVO setmealVO = setmealService.byIdSelectSetmeal(id);
        return Result.success(setmealVO);
    }

    @ApiOperation("修改套餐的功能")
    @PutMapping
    public Result updateSetmeal(@RequestBody SetmealDTO setmealDTO) {

        log.info("正在执行修改套餐的方法.....修改的信息为:{}", setmealDTO);

        setmealService.updateSetmeal(setmealDTO);

        return Result.success();
    }

    @ApiOperation("套餐状态启用或禁用功能")
    @PostMapping("/status/{status}")
    public Result statusStartOrStop(Long id, @PathVariable Integer status) {

        log.info("正在执行套餐状态启用或禁用方法.....需要修改的套餐id为:{},修改的状态为:{}", id, status);

        setmealService.statusStartOrStop(id, status);

        return Result.success();

    }

    @ApiOperation("新增套餐的功能")
    @PostMapping
    public Result insertSetmeal(@RequestBody SetmealDTO setmealDTO) {

        log.info("正在执行新增套餐的功能......新增的信息为:{}", setmealDTO);

        setmealService.insertSetmeal(setmealDTO);

        return Result.success();

    }

    @ApiOperation("删除套餐的功能")
    @DeleteMapping
    public Result deleteSetmeal(@RequestParam List<Long> ids) {

        log.info("正在执行删除套餐的方法.....删除的id为{}", ids);

        setmealService.deleteSetmeal(ids);

        return Result.success();
    }
}
